package com.qiangqiang.task.server.mapper.provider;

import com.qiangqiang.task.server.entity.Moments;

import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @program: task
 * @description:
 * @author: Sky.lin
 * @create: 2019-01-05 20:54
 **/
public class MomentsProvider extends BaseProvider {


    public String insertMoments(final Map<String, Object> map) {
        Moments moments = (Moments) map.get("moments");
        return generateInsertSQL(Moments.class);
    }

    public String queryAllMomentsByFollowId(final Map<String, Object> map) {
        final int page = (int) map.get("page");
        final int pageSize = (int) map.get("pageSize");
        final Set<Long> idLists = (Set<Long>) map.get("idList");


        StringBuffer sb = new StringBuffer("select * from moments where user_id in (");
        //构造 范围查找语句 in
        sb.append(String.join(",", idLists.stream().
                map(String::valueOf).collect(Collectors.toList()))).append(")");
        sb.append(" order by update_time desc ");
        //分页查找
        sb.append(getLimit(page, pageSize));
        return sb.toString();
    }
}
